package cn.edu.guet.controller;

import cn.edu.guet.bean.Mypost.Mypost;
import cn.edu.guet.service.Mypost.IMypostService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Controller
//@RequestMapping("mypost")
public class MypostController {

    @Autowired
    private IMypostService mypostService;


    @GetMapping("mypost/zuixinremen")
    public String zuixinremen(HttpServletRequest request, Model model){
        String userid = (int)request.getSession().getAttribute("userid")+"";
        String ptitle=request.getParameter("ptitle");
        String ptype=request.getParameter("ptitle");
        System.out.print("AAAAA:"+ptitle);
        List<Mypost> myposts=mypostService.zuixinremen(userid,ptitle,ptype);
        model.addAttribute("myposts",myposts);
        return "zuixinremen";
    }


    @GetMapping("mypost/xinfabiao")
    public String zuixinfabiao(HttpServletRequest request, Model model){
        String userid = (int)request.getSession().getAttribute("userid")+"";
        String ptitle=request.getParameter("ptitle");
        String ptype=request.getParameter("ptitle");
        System.out.print("AAAAA:"+ptitle);
        List<Mypost> myposts=mypostService.xinfabiao(userid,ptitle,ptype);
        model.addAttribute("myposts",myposts);
        return "xinfabiao";


    }


    @GetMapping("mypost/mokuai")
    public String mokuai(HttpServletRequest request, Model model){
        // request.getSession().getAttribute("tid");
        String tid = request.getParameter("tid");
        System.out.println(tid);
//        tid = "1";
        String ptitle=request.getParameter("ptitle");
        String ptype=request.getParameter("ptitle");
        System.out.print("AAAAA:"+ptitle);
        List<Mypost> myposts=mypostService.mokuai(tid,ptitle,ptype);
        model.addAttribute("myposts",myposts);
        model.addAttribute("page","mokuai");
        return "forward:/main";

    }

    @GetMapping(value = "mypost/search")
    public String search( HttpServletRequest request,Model model) {
        String userid = (int)request.getSession().getAttribute("userid")+"";
        String ptitle=request.getParameter("ptitle");
        String ptype=request.getParameter("ptitle");
        System.out.print("AAAAA:"+ptitle);
        List<Mypost> myposts=mypostService.search(userid,ptitle,ptype);
        model.addAttribute("myposts",myposts);
        model.addAttribute("page","search");
        return "forward:/main";
    }



}


